<!--
* description: 备件信息管理111-新增弹窗
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="标签打印数量"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      @close="sendCode"
      width="400px"
    >
      <dialogHeader slot="title" title="标签打印数量" :styleType="$store.state.app.dialogType"></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :isMul="comp.isMul"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :dateOptionsType="comp.dateOptionsType"
            :dataToObject="comp.dataToObject"
            :readonly="comp.readonly"
            :placeholder="comp.placeholder"
            :isInput="comp.isInput"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
    <print v-if="isShow" :formField="formField" @detailClose="detailClose" :isShow="isShow" />
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import { wmsApis } from "@/api/wms/baseData/api";
import storage from "@/utils/storage";
import request from "@/utils/request";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader"), //弹窗标题
    print: () => import("./print")
  },
  watch: {
    popupsVisible(val) {
      if (val) {
        if (
          this.formField.pageId !== "" &&
          this.$route.query.pageId !== undefined &&
          this.$route.query.pageId !== this.formField.pageId
        ) {
          this.formField.pageId = this.$route.query.pageId;
          this.formField.pageName = this.$route.query.pageName;
        }
        this.formField.langLabelName = this.formField.label;
        this.backFormField = JSON.parse(JSON.stringify(this.formField));
        this.querySelect;
      }
    }
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: wmsApis.savePartList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.print(),
          text: "标签打印"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey1",
          labelName: "打印数量",
          span: 23,
          codeField: "printNum",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          changed: val => {
            if (!val) {
              return;
            }
            if (this.formField.printNum < 1) {
              this.$refs["edit_compKey1"][0].modelCode = 1;
              this.formField.printNum = 1;
            }
            this.$refs["edit_compKey1"][0].modelCode = (
              this.formField.printNum + ""
            ).replace(/[^\d]/g, "");
            this.formField.printNum = (this.formField.printNum + "").replace(
              /[^\d]/g,
              ""
            );
          }
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        printNum: "",
        PART_NO: "",
        PART_NAME: "",
        SNP_IN: "",
        SNP_OUT: "",
        SUPPLIER_CODE: "",
        ADDRESS: ""
      },
      // 控制打印弹窗
      isShow: false
    };
  },
  methods: {
    //打印
    print() {
      if (!this.formField.printNum) {
        this.$message({
          message: "请输入打印数量"
        });
        return;
      }
      this.isShow = true;
    },
    detailClose() {
      this.isShow = false;
    }
  }
};
</script>
<style type="text/css" scoped>
.filter-params .el-col label .curName {
  width: 150px;
}
</style>